#!/usr/bin/python
# File server_config.py

import ini
import sys
import const

class CommunicationConfig:
    """Configuer the communication stuff

    Read communication arguments from the 'communication.ini' file.
    The different lib of xmpp may have a different parameter request.
    So, this class need reimpelemt for other lib. 
    """
    def __init__( self ):
        ini_parser = ini.Ini()
        if not ini_parser.parse( const.CONFIG_FILE_NAME ):
            sys.stderr.write( ini_parser.reportError() )
            sys.exit( -1 )

        self.jid = ini_parser.read_string( 'configuration', 'jid' )
        self.server = ini_parser.read_string( 'configuration', 'server' )
        self.port = ini_parser.read_string( 'configuration', 'port' )
        self.passwd = ini_parser.read_string( 'configuration', 'passwd' )
        self.debug = ini_parser.read_string( 'configuration', 'debug' )

        if not ( self.jid and self.server and self.port ):
            sys.stderr.write( const.CONFIG_NOT_COMPELET )
            sys.exit( -1 )

        tempList = self.jid.split( '@' )

        if len( tempList ) != 2:
            sys.stderr.write( const.CONFIG_NOT_COMPELET ) 
            exit( -1 )
            
        self.username, self.domain = tempList
        self.resource = const.RESOURCE_NAME

def main():
    comm = CommunicationConfig()
    print comm.domain
    print comm.server
    print comm.port
    print comm.username
    print comm.passwd
    pass

if __name__ == '__main__':
    main()

# End of server_config.py
